/**
 * 
 */
package hk.edu.cityu.is.riskmgmt.agent;

import hk.edu.cityu.is.riskmgmt.data.SharedData;
import hk.edu.cityu.is.riskmgmt.interfaces.Agent;

import org.apache.log4j.Logger;

/**
 * @author chaolu
 * 
 */
public class BankAgent implements Agent {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(BankAgent.class);

	private int no;

	public BankAgent(int no) {
		super();
		this.no = no;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public SharedData step(SharedData sd) {
		// TODO Auto-generated method stub
		if (logger.isInfoEnabled()) {
			logger.info("step(SharedData) - I am a bank:" + this.no); //$NON-NLS-1$
		}
		if (sd.getIsDefault()[this.no]) {
			// default
			// when default, the bank will sell all trading assets for cash.
			sd.setOneBankCash(no,
					sd.getOneBankCash(no) + sd.getOneBankTradingAssets(no));
			sd.setOneBankTradingAssets(no, 0);
		} else {
			// non-default
			// buy trading assets
			// if (sd.getOneBankTradingAssets(no) > 1) {
			if (sd.getBank_cash()[no] > 0) {
				// double amount = sd.getBank_cash()[no];
				sd.setOneBankTradingAssets(no, sd.getOneBankTradingAssets(no)
						+ sd.getOneBankCash(no) * 0.2);
				sd.setOneBankCash(no, sd.getOneBankCash(no) * 0.8);
			}
		}

		// }
		return sd;

	}

	public BankAgent() {
		super();
		// TODO Auto-generated constructor stub
	}
}
